package com.jshx.sz.gdjt.thread;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ConnectTimeoutException;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.json.JSONArray;
import org.json.JSONObject;

import com.jshx.sz.gdjt.util.AccessDBImp;
import com.jshx.sz.gdjt.util.TDESEncodeUtils;
import com.jshx.sz.gdjt.constant.ApplicationGlobal;

import android.content.pm.PackageInfo;
import android.os.Handler;
import android.os.Message;
 

public class RebackTaskThread  extends Thread{
	private Handler handler;
	private String params;
	private HashMap  returnMap = new HashMap ();
	
	private String orderNos;
	private String type;
	private ArrayList taskList;
	
	public RebackTaskThread()
	{
		
	}
	public RebackTaskThread(Handler handler, String params, HashMap  data,String type,ArrayList taskList,String orderNos)
	{
		this.handler=handler;
		this.params=params;
		this.returnMap=data;
		
		this.type=type;
		this.taskList=taskList;
		this.orderNos=orderNos;
	}
	public void run() 
	{
		try {
			AccessDBImp dao= new AccessDBImp();
			String re=dao.proDB("updateTask", params);
			HashMap map=new HashMap();
			map=dao.splitDataHashMap(re);
			dao.dataCopyHashMapToHashMap(map, returnMap);
			
			
			if(this.type.equals("task"))//如果是领取任务的话，返回列表信息给本地用来处理离线列表
			{
				params= ",'userId':'"+ApplicationGlobal.userId+"','type':'getTaskList_lx','orderNos':'"+this.orderNos+"'";
				re=dao.proDB("getTaskList_lx", params);
				ArrayList alist=new ArrayList ();
				alist=dao.splitDataList(re);
				dao.dataCopyArrayListToArrayList(alist, taskList);
			}
			
			
			Message msg=new Message();
			msg.what=ApplicationGlobal.data_obtained;
			handler.sendMessage(msg) ;
		} catch (Exception e) {
			System.out.println(e);
			e.printStackTrace();
			Message msg=new Message();
			msg.what=ApplicationGlobal.data_missed;
			handler.sendMessage(msg) ;
		}  
	}
	 
	
	 
}
